Skip to content

Add proxy support: honor system proxy and HTTPS_PROXY/HTTP_PROXY/NO_PROXY#19

Merged
rodchristiansen merged 4 commits into
mainfrom
proxy-support
May 12, 2026
Merged

Add proxy support: honor system proxy and HTTPS_PROXY/HTTP_PROXY/NO_PROXY#19
rodchristiansen merged 4 commits into
mainfrom
proxy-support

Conversation

@rodchristiansen
Copy link
Copy Markdown
Owner

Summary

  • Drop the connectionProxyDictionary = [:] override in APIClient so URLSession honors the macOS system proxy / PAC by default, fixing the unusable-behind-corp-proxy case reported in FR: Add proxy support #16.
  • Add explicit HTTPS_PROXY / HTTP_PROXY / NO_PROXY env-var support for headless and CI environments where system proxy isn't configured.
  • Remove the dead Sources/asbmutil/ directory left over from PR Ship ASBMUtil.app: native SwiftUI front-end + tag-only releases #15's layout move (not referenced by Package.swift or anything else).
  • Document the new behavior under a "Network proxy" section in the README.

NO_PROXY is matched against account.apple.com (auth) and the scope-specific API host (api-business.apple.com or api-school.apple.com). If every host this client reaches is bypassed, the env-var proxy is skipped so system proxy applies. Lowercase variants (https_proxy, etc.) are honored too.

Proxy authentication relies on system credentials (Negotiate/Kerberos); user:pass-in-URL embedding is not extracted in this PR — happy to add a follow-up if needed.

Closes #16.

Test plan

  • swift build succeeds
  • Unset env vars, run asbmutil list-mdm-servers against a tenant on a network without a system proxy — should work as before
  • Set HTTPS_PROXY=http://localhost:8080 pointing at a local proxy (mitmproxy/Charles), run a command — traffic should flow through the proxy
  • With the env-var proxy set plus NO_PROXY=*.apple.com, the env-var proxy should be skipped and the request should bypass it
  • On a Mac with macOS system proxy / PAC configured, with no env vars set — traffic should follow the system proxy

Copilot AI review requested due to automatic review settings May 7, 2026 18:48
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the networking layer to better support corporate/headless proxy setups, while also hardening credential input handling and cleaning up legacy source layout.

Changes:

  • Update URLSession setup to honor macOS system proxy/PAC by default and add HTTPS_PROXY/HTTP_PROXY + NO_PROXY env-var support.
  • Sanitize OAuth identifiers (client ID / key ID) to avoid clipboard newline/whitespace issues and validate single-line constraints in CLI/App entry points.
  • Remove the unused legacy Sources/asbmutil/ implementation and document proxy behavior in the README.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
Sources/core/Utilities/StringSanitization.swift Adds a shared string sanitization helper for identifiers.
Sources/core/Auth/Creds.swift Applies identifier sanitization when loading credentials and deriving scope.
Sources/core/API/APIClient.swift Removes proxy-disabling session; adds env-var proxy handling and NO_PROXY logic.
Sources/cli/ConfigCommand.swift Sanitizes and validates identifier inputs before saving credentials.
Sources/app/Views/Settings/SettingsView.swift Sanitizes identifiers when creating a new profile in the UI.
Sources/app/ViewModels/SettingsViewModel.swift Sanitizes/validates identifiers on save with a user-facing error state.
README.md Documents system proxy + env-var proxy behavior and examples.
Sources/asbmutil/FileCredentialStore.swift Removes legacy file-based credential store implementation.
Sources/asbmutil/APIClient.swift Removes legacy API client implementation that disabled system proxy.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Sources/core/API/APIClient.swift Outdated
func bypassed(_ host: String) -> Bool {
let h = host.lowercased()
return bypass.contains { pattern in
let p = pattern.hasPrefix(".") ? String(pattern.dropFirst()) : pattern
Comment thread README.md
Comment on lines +622 to +625
```bash
export HTTPS_PROXY=http://proxy.corp.example:8080
export NO_PROXY=*.internal.example,localhost
```
Comment on lines +156 to 160
}

HStack {
Button("Cancel") { showNewProfile = false }
.keyboardShortcut(.cancelAction)
Leftover from PR #15's move to Sources/core/. Not referenced by
Package.swift or anything else in the repo, so it never compiled.
The previous code force-disabled proxies by setting
connectionProxyDictionary to an empty dictionary, which made the tool
unusable in environments that require an HTTP proxy for outbound
traffic and ignored standard proxy env vars even when set.

Drop the override so URLSession uses the macOS system proxy / PAC by
default, and add explicit HTTPS_PROXY / HTTP_PROXY / NO_PROXY env-var
support for headless and CI use. NO_PROXY is matched against the auth
host (account.apple.com) and the scope-specific API host; if every
host is bypassed, the env-var proxy is skipped and system proxy
applies.

Closes #16
Treat `*.foo.com` the same as `.foo.com` and `foo.com` for NO_PROXY
matching, since the README and common curl/Docker NO_PROXY conventions
use the `*.` form. Without this, `NO_PROXY=*.apple.com` failed to bypass
the auth and API hosts as the example in the README implied.
kCFNetworkProxiesHTTPSEnable/Proxy/Port are CoreFoundation constants
unavailable on swift-corelibs-foundation. On Linux, fall through to the
default URLSessionConfiguration which already honors HTTP(S)_PROXY env
vars via the underlying networking stack.
@rodchristiansen rodchristiansen merged commit eeee657 into main May 12, 2026
2 checks passed
@rodchristiansen rodchristiansen deleted the proxy-support branch May 12, 2026 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FR: Add proxy support

2 participants